/*
 * @Descripttion: 组件业务名
 * @version:
 * @Author: lhl
 * @Date: 2024-11-18 23:26:41
 * @LastEditors: lhl
 * @LastEditTime: 2024-11-18 23:26:53
 */
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface MenuItem {
  path: string;
  meta: {
    title: string;
    icon?: string;
  };
  children?: MenuItem[];
}

interface MenuState {
  menuList: MenuItem[];
  collapsed: boolean;
}

const initialState: MenuState = {
  menuList: [],
  collapsed: false,
};

const menuSlice = createSlice({
  name: 'menu',
  initialState,
  reducers: {
    setMenuList: (state, action: PayloadAction<MenuItem[]>) => {
      state.menuList = action.payload;
    },
    toggleCollapsed: (state) => {
      state.collapsed = !state.collapsed;
    },
  },
});

export const { setMenuList, toggleCollapsed } = menuSlice.actions;
export default menuSlice.reducer;
